﻿@using AtletIS.Shared.Helpers
@model MvcAtletIS.Models.LiveModel
@if (Model != null)
{ 
    <div id="main">
        
        <!-- HEADER -->
        <div class="header-info">
            <p class="float-right">@ViewRes.SharedStrings.ChipResults</p>
            <p class="align-left"><strong>@Model.ActiveDiscipline.Name</strong></p>
        </div>

        <!-- CHECK POINTS -->
        <div id="col1">
            <ul style="height: 342px;">
                @if (Model.CheckPoints != null && Model.CheckPoints.Count > 0)
                {
                    foreach (var item in Model.CheckPoints)
                    {
                        if (item.ID == Model.ActiveCheckPoint.ID)
                        {
                            <li id="chkActive" style="background: #ddd;">
                                @Html.ActionLink(item.Name, "Index", new { CompetitionId = Model.ActiveCompetition.ID, DisciplineId = Model.ActiveDiscipline.ID, CheckPointId = item.ID, Code = Model.Code })
                            </li>
                        }
                        else
                        {
                            <li>
                                @Html.ActionLink(item.Name, "Index", new { CompetitionId = Model.ActiveCompetition.ID, DisciplineId = Model.ActiveDiscipline.ID, CheckPointId = item.ID, Code = Model.Code })
                            </li>
                        }
                    }
                }
            </ul>
        </div>
        
        <!-- CHIP DATA -->
        <div id="col2">
            <ul>
                @if (Model.ChipData != null && Model.ChipData.Count > 0)
                {
                    int rank = (Model.ChipData.PageNumber - 1) * 8 + 1; 
                    foreach (var item in Model.ChipData)
                    { 
                        <li class="main-info-small">
                        
                            <!-- Rank -->
                            <div class="order-box-small">@rank</div>

                            <img class="picture-box-small" src="@Url.Content("~/Content/flags/24px/" + item.CountryId + ".png")" alt="@item.CountryId" height="18px" />
                        
                            <!-- StartNumber -->
                            @if (item.StartNumber != 0)
                            {
                                <div class="lane-box-small">(@item.StartNumber)</div>
                            }
                            else
                            {
                                <div class="lane-box-small">&zwnj;</div>
                            }

                            <div class="name-box-small">@item.Surname.ToUpper() @item.FirstName</div>

                            <!-- Result -->
                            <div class="result-box-small">@PrintHelper.PrintResult(TimeSpanHelper.ToResultString(item.ChipDateTimeSpan), Model.ActiveDiscipline.DisciplineCode.Value)</div>
                        
                        </li>
                    
                            rank += 1;
                    }
                }
            </ul>
        </div> <!-- CHIP DATA -->

        <!-- FOOTER -->
        <div class="footer-info">
            <p class="float-left">@ViewRes.SharedStrings.Start: @Model.ActiveDiscipline.OfficialStartTime</p>
            <p class="float-right">@ViewRes.SharedStrings.Page: @(Model.ChipData.PageCount < Model.ChipData.PageNumber ? 0 : Model.ChipData.PageNumber) / @Model.ChipData.PageCount</p>
            <p class="align-center">&copy AtletIS @DateTime.Now.Year</p>
        </div>

        <!-- LOGO -->
        <div id="logo-box">
            <a href="http://www.hrdosport.sk" target="_blank"><img src="@Url.Content("~/Content/hrdosport_live.png")" alt="Hrdošport" height="40px" /></a>
        </div>

        <!-- PAGING -->
        <div id="paging-box">
            @if (Model.ChipData.HasNextPage)
            {
                @Html.ActionLink(">>", "Index", new { CompetitionId = Model.ActiveCompetition.ID, DisciplineId = Model.ActiveDiscipline.ID, CheckPointId = Model.ActiveCheckPoint.ID, Page = Model.ChipData.PageCount, Code = Model.Code })
                @Html.Raw(" ");
                @Html.ActionLink(">", "Index", new { CompetitionId = Model.ActiveCompetition.ID, DisciplineId = Model.ActiveDiscipline.ID, CheckPointId = Model.ActiveCheckPoint.ID, Page = Model.ChipData.PageNumber + 1, Code = Model.Code })
            }
                
            @if (Model.ChipData.HasPreviousPage)
            {
                @Html.ActionLink("<", "Index", new { CompetitionId = Model.ActiveCompetition.ID, DisciplineId = Model.ActiveDiscipline.ID, CheckPointId = Model.ActiveCheckPoint.ID, Page = Model.ChipData.PageNumber - 1, Code = Model.Code })
                @Html.Raw(" ");                        
                @Html.ActionLink("<<", "Index", new { CompetitionId = Model.ActiveCompetition.ID, DisciplineId = Model.ActiveDiscipline.ID, CheckPointId = Model.ActiveCheckPoint.ID, Page = 1, Code = Model.Code })
            }
        </div>

    </div>
    
    <script type="text/javascript">

        $(function () {
            $("#col1").animate({
                scrollTop: $("#chkActive").offset().top - $("#col1").offset().top - 3
            }, 0);
        });

    </script>
}